#include <QtGui>

#include "cuboidDialog.h"
#include "src/vector3d.h"

CuboidDialog::CuboidDialog(int _id, QWidget *_parent)
    : ObjectDialog(_id, _parent){
    setWindowTitle(QString::fromUtf8("Criando polígono ").append(QString::number(_id)));

    sideLength = 1;

    createLayout();
}

CuboidDialog::~CuboidDialog(){
}

void CuboidDialog::createLayout(){
    QDoubleSpinBox *sideLengthDoubleSpinBox = new QDoubleSpinBox();
    sideLengthDoubleSpinBox->setRange(0.1, 50.0);
    sideLengthDoubleSpinBox->setSingleStep(1.0);
    sideLengthDoubleSpinBox->setValue(sideLength);
    connect(sideLengthDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(changeSideLength(double)));

    QHBoxLayout *sideLengthLayout = new QHBoxLayout;
    sideLengthLayout->addWidget(sideLengthDoubleSpinBox);
    sideLengthLayout->addStretch(1);

    QGroupBox *sideLengthGroupBox = new QGroupBox(QString::fromUtf8("Tamanho do lado: "));
    sideLengthGroupBox->setLayout(sideLengthLayout);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(sideLengthGroupBox);
    mainLayout->addLayout(createColorButtonLayout());
    mainLayout->addStretch(1);

    setLayout(mainLayout);
}

void CuboidDialog::acceptAndCreate(){
    if(!object){
        object = new Object(id);
        object->makeCuboid(sideLength, Color(colorR / 255.0, colorG / 255.0, colorB / 255.0, colorAlpha / 255.0));
    }
    else if(colorChanged)
    {
        object->setColor(Color(colorR / 255.0, colorG / 255.0, colorB / 255.0, colorAlpha / 255.0));
    }


    emit done(object, CUBOID);
    accept();
}

void CuboidDialog::changeSideLength(double _l){
    sideLength = _l;
}
